From 8a085e9d947609b4baf3ed57007a3aab481f0155 Mon Sep 17 00:00:00 2001 From: Konrad Rzeszutek Wilk Date: Mon, 22 Aug 2016 14:41:41 -0400 Subject: [PATCH] x86,arm: Change arch_livepatch_quiesce() declaration. On ARM we need an alternative VA region to poke in the hypervisor .text data. And since this is setup during runtime we may fail (it uses vmap so most likely error is ENOMEM). As such this error needs to be bubbled up and also abort the livepatching if it occurs. Reviewed-by: Andrew Cooper Reviewed-by: Julien Grall Signed-off-by: Konrad Rzeszutek Wilk --- xen/arch/arm/livepatch.c | 3 ++- xen/arch/x86/livepatch.c | 4 +++- xen/common/livepatch.c | 16 ++++++++++++++-- xen/include/xen/livepatch.h | 2 +- 4 files changed, 20 insertions(+), 5 deletions(-) diff --git a/xen/arch/arm/livepatch.c b/xen/arch/arm/livepatch.c index aba13204f9..755f59686f 100644 --- a/xen/arch/arm/livepatch.c +++ b/xen/arch/arm/livepatch.c @@ -7,8 +7,9 @@ #include #include -void arch_livepatch_quiesce(void) +int arch_livepatch_quiesce(void) { + return -ENOSYS; } void arch_livepatch_revive(void) diff --git a/xen/arch/x86/livepatch.c b/xen/arch/x86/livepatch.c index 39620f9967..725b3f636d 100644 --- a/xen/arch/x86/livepatch.c +++ b/xen/arch/x86/livepatch.c @@ -15,10 +15,12 @@ #define PATCH_INSN_SIZE 5 -void arch_livepatch_quiesce(void) +int arch_livepatch_quiesce(void) { /* Disable WP to allow changes to read-only pages. */ write_cr0(read_cr0() & ~X86_CR0_WP); + + return 0; } void arch_livepatch_revive(void) diff --git a/xen/common/livepatch.c b/xen/common/livepatch.c index 282da743a8..23e4d51522 100644 --- a/xen/common/livepatch.c +++ b/xen/common/livepatch.c @@ -1004,11 +1004,17 @@ static int livepatch_list(xen_sysctl_livepatch_list_t *list) static int apply_payload(struct payload *data) { unsigned int i; + int rc; printk(XENLOG_INFO LIVEPATCH "%s: Applying %u functions\n", data->name, data->nfuncs); - arch_livepatch_quiesce(); + rc = arch_livepatch_quiesce(); + if ( rc ) + { + printk(XENLOG_ERR LIVEPATCH "%s: unable to quiesce!\n", data->name); + return rc; + } for ( i = 0; i < data->nfuncs; i++ ) arch_livepatch_apply_jmp(&data->funcs[i]); @@ -1028,10 +1034,16 @@ static int apply_payload(struct payload *data) static int revert_payload(struct payload *data) { unsigned int i; + int rc; printk(XENLOG_INFO LIVEPATCH "%s: Reverting\n", data->name); - arch_livepatch_quiesce(); + rc = arch_livepatch_quiesce(); + if ( rc ) + { + printk(XENLOG_ERR LIVEPATCH "%s: unable to quiesce!\n", data->name); + return rc; + } for ( i = 0; i < data->nfuncs; i++ ) arch_livepatch_revert_jmp(&data->funcs[i]); diff --git a/xen/include/xen/livepatch.h b/xen/include/xen/livepatch.h index 02f4572fb5..243e240511 100644 --- a/xen/include/xen/livepatch.h +++ b/xen/include/xen/livepatch.h @@ -71,7 +71,7 @@ int arch_livepatch_verify_func(const struct livepatch_func *func); * These functions are called around the critical region patching live code, * for an architecture to take make appropratie global state adjustments. */ -void arch_livepatch_quiesce(void); +int arch_livepatch_quiesce(void); void arch_livepatch_revive(void); void arch_livepatch_apply_jmp(struct livepatch_func *func); -- 2.30.2